package com.zyp.boot05.controller;

import com.zyp.boot05.entity.User;
import com.zyp.boot05.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public String reg(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "用户已存在！请<a href='/reg.html'>重新注册</a>。";
        }
        mapper.insert(user);
        return "注册成功！<a href='/'>返回首页</a>";
    }

    @RequestMapping("/login")
    public String login(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u==null){
            return "用户名不存在！";
        }
        if (user.getPassword().equals(u.getPassword())){
            return "登录成功！";
        }
        return "密码错误！";
    }
}
